package com.example.study_mybatis.mapper;

import com.example.study_mybatis.model.User;
import org.apache.ibatis.annotations.*;

public interface UserMapper {

    @Select("select * from user where id = #{id}")
    @Results(
            value = {
                    @Result(id = true, column = "id", property = "id"),
                    @Result(column = "school_name", property = "schoolName"),
                    @Result(property = "addressList",column = "id",many = @Many(
                            select = "com.example.study_mybatis.mapper.AddressMapper.listByUserId"
                    ))
            }
    )
    User selectById(Integer id);

    @Delete("delete from user where id = #{id}")
    int delete(Integer id);

    @Insert("insert into user (username, password, nickname, age, birthday, school_name) value (#{username},#{password},#{nickname},#{age},#{birthday},#{schoolName})")
    int insert(User user);

    @Update("update user set username = #{username},nickname = #{nickname} where id = #{id}")
    int update(User user);
}
